package com.example.welcome;

import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ImageView;

public class MainActivity extends AppCompatActivity {
    ImageView imageView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        imageView = (ImageView) findViewById(R.id.img_welcome);

        AnimatorSet set=new AnimatorSet();
        ObjectAnimator translationY=ObjectAnimator.ofFloat(imageView,"translationY",0,300);
//代表自身顺时针旋转从0度旋转360度
        ObjectAnimator rotation=ObjectAnimator.ofFloat(imageView,"rotation",0,360);
//代表沿X轴从0度旋转360度
        ObjectAnimator rotationX=ObjectAnimator.ofFloat(imageView,"rotationX",0,360);
//设置动画的时长，2000代表在2秒内完成
        set.setDuration(3000);
//把动画放到AnimatorSet 中
        set.playTogether(translationY,rotation,rotationX);
//执行动画
        set.start();


        //welcome 指的是xml文件的名字
        SharedPreferences setting = getSharedPreferences("welcome", 0);

        Boolean user_first = setting.getBoolean("FIRST", true);
        if (user_first) {// 第一次则跳转到欢迎页面
            setting.edit().putBoolean("FIRST", false).commit();
            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    startActivity(new Intent(MainActivity.this, Main2Activity.class));
                    finish();
                }
            }, 3000);
        } else {//如果是第二次启动则直接跳转到主页面
            startActivity(new Intent(this, Main2Activity.class));
            finish();
        }
    }
}
